use strict;
use Stdlog;
use File::Spec;
use Test::More tests => 9;

# Test 1 -- use Stdlog::Writer
BEGIN { use_ok('Stdlog::Writer');}

my $writer;

# Test 2 -- create STDERR writer
$writer = Stdlog::Writer->new({writer => 'STDERR'});
ok($writer && ref($writer) eq 'Stdlog::Writer::STDERR',
    "Created Stdlog::Writer::STDERR");

# Test 3 -- create File writer
$writer = Stdlog::Writer->new({writer => 'File'});
ok($writer && ref($writer) eq 'Stdlog::Writer::File',
    "Created Stdlog::Writer::File");

# Test 4 -- create implicit File writer
$writer = Stdlog::Writer->new({filename => 'foo.log'});
ok($writer && ref($writer) eq 'Stdlog::Writer::File',
    "Created implicit Stdlog::Writer::File");

SKIP: {
    eval { require Sys::Syslog };
    skip "No Sys::Syslog", 1 if $@;

    # Test 5 -- create Syslog writer
    $writer = Stdlog::Writer->new({writer => 'Syslog'});
    ok($writer && ref($writer) eq 'Stdlog::Writer::Syslog',
        "Created Stdlog::Writer::Syslog");
}

SKIP: {
    eval { require IO::Socket };
    skip "No IO::Socket", 2 if $@;

    # Test 6 -- create Socket writer
    $writer = Stdlog::Writer->new({writer => 'Socket'});
    ok($writer && ref($writer) eq 'Stdlog::Writer::Socket',
        "Created Stdlog::Writer::Socket");
    
    # Test 7 -- create implicit Socket writer
    $writer = Stdlog::Writer->new({'socket' => 'hostname:8080'});
    ok($writer && ref($writer) eq 'Stdlog::Writer::Socket',
        "Created implicit Stdlog::Writer::Socket");
}

SKIP: {
    eval{ require DBI; };
    skip "No DBI", 2 if $@;
    
    # Test 8 -- create DBI writer
    $writer = Stdlog::Writer->new({writer => 'DBI'});
    ok($writer && ref($writer) eq 'Stdlog::Writer::DBI',
        "Created Stdlog::Writer::DBI");
    
    # Test 9 -- create implicit DBI writer
    $writer = Stdlog::Writer->new({dsn => 'dbi:foo:bar'});
    ok($writer && ref($writer) eq 'Stdlog::Writer::DBI',
        "Created implicit Stdlog::Writer::DBI");
}

